package com.kkb.controller;

import com.github.pagehelper.PageInfo;
import com.kkb.pojo.Doctor;
import com.kkb.pojo.Hosregister;
import com.kkb.service.DoctorService;
import com.kkb.vo.DoctorQueryVO;
import com.kkb.vo.RegistrationQueryVO;
import com.kkb.vo.ResultVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Controller
@RequestMapping("doctor")
@ResponseBody
public class DoctorController {
    @Resource
    private DoctorService doctorService;

    @RequestMapping(value = "list", method = RequestMethod.GET)
    public ResultVO<Doctor> queryByPage(@RequestParam(defaultValue = "1") Integer realPageNum, @RequestParam(defaultValue = "5") Integer pageSize, DoctorQueryVO vo) {
        PageInfo<Doctor> info = doctorService.queryByPage(realPageNum, pageSize, vo);
        return new ResultVO<>(info);
    }

    @RequestMapping(value = "/id/{id}", method = RequestMethod.GET)
    public ResultVO<Doctor> queryById(@PathVariable("id") Integer id) {
        Doctor doctor = doctorService.queryById(id);
        return new ResultVO<>(doctor);
    }

    @RequestMapping(value = "/update/{id}", method = RequestMethod.PUT)
    public ResultVO<Doctor> updateDoctor(@PathVariable("id") Integer id, Doctor doctor) {
        doctor.setId(id);
        int i = doctorService.updateDoctor(doctor);
        if (i == 1) {
            return new ResultVO<Doctor>();
        }
        return new ResultVO<Doctor>(500, "服务器内部异常，请稍后再试！");
    }

    @RequestMapping(value = "", method = RequestMethod.POST)
    public ResultVO<Doctor> addDoctor(Doctor doctor) {
        int i = doctorService.addDoctor(doctor);
        if (i == 1) {
            return new ResultVO<Doctor>();
        }
        return new ResultVO<Doctor>(500, "服务器内部异常，请稍后再试！");
    }
}
